<!--  -->
<template>
    <div class="float-left" v-if="hl && hl.date">
        <div class="mb-2 text-white text-sm text-left">
            {{ hl.date }}|{{ hl.week }}
        </div>
        <div class="mb-2 text-yellow-300 text-sm text-left">
            {{ hl.lunarDate }}
        </div>
        <div class="mb-2 text-orange-300 text-sm text-left">
            {{ hl.ganZhi }}
        </div>
    </div>
</template>

<script>
import ax from "../ax";

let { get } = ax;
export default {
    data() {
        return {
            hl: null,
            UpdateTimer: null
        };
    },

    components: {},

    computed: {},

    mounted() {

        this.scheduleGetUserLocation();
    },
    beforeDestroy() {
        clearInterval(this.UpdateTimer);
    },
    created() { this.getDate(); },

    methods: {
        scheduleGetUserLocation() {
            const now = new Date();
            const nextHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1, 0, 1, 0);
            const delay = nextHour - now;

            setTimeout(() => {
                this.getUserLocation();
                this.UpdateTimer = setInterval(this.getDate.bind(this), 1000 * 60 * 60);
            }, delay);
        },
        getDate() {
            get("/api/Rss/GetLunarDate", {}).then((res) => {
                this.hl = res;
                this.hl.ryi = this.hl.yj[0].join(', ');
                this.hl.ryilist = this.hl.ryi.split(',')
                this.hl.rji = this.hl.yj[1].join(', ');
                this.hl.rjilist = this.hl.rji.split(',')
                this.hl.syi = this.hl.yj[2].join(', ');
                this.hl.syilist = this.hl.syi.split(',')
                this.hl.sji = this.hl.yj[3].join(', ');
                this.hl.sjilist = this.hl.sji.split(',')

                console.log(this.hl)

            }).catch(error => {
                // 错误处理逻辑

            });
        },

    }
}

</script>
<style lang='scss' scoped></style>